﻿/*=======================================================================================
	TASK 5:                                                   {Using Classes and Objects}
	Write a method that calculates the number of workdays between today and given date,
    passed as parameter. Consider that workdays are all days from Monday to Friday except
    a fixed list of public holidays specified preliminary as array.
=======================================================================================*/

using System;

namespace _05.WorkDays
{
    class WorkDays
    {
        static void Main()
        {
            DateTime today = DateTime.Today;
            Console.WriteLine("today:{0}",today);

            Console.Write("Enter final date DD.M.YYYY:");
            DateTime endDay = DateTime.Parse(Console.ReadLine());
            //DateTime endDay = DateTime.Today.AddDays(9);
            Console.WriteLine("end date:{0}", endDay);

            int workDays = WorkDaysInPeriod(today, endDay);
            Console.WriteLine("number of workdays is:{0}", workDays);
        }

        static int WorkDaysInPeriod(DateTime startDay, DateTime endDay)
        {
            DateTime[] holidays = 
            {
                new DateTime(startDay.Year, 1, 1), // January the 1st
                new DateTime(startDay.Year, 3, 3), // Marth the 3rd
                new DateTime(startDay.Year, 5, 1), // Labor day
                new DateTime(startDay.Year, 5, 6), // Georgeday
                new DateTime(startDay.Year, 5, 24), // St. Kiril i Metodii
                new DateTime(startDay.Year, 9, 6), // Union
                new DateTime(startDay.Year, 9, 22), // Indepence
                new DateTime(startDay.Year, 11, 1), // Buditeli
                new DateTime(startDay.Year, 12, 24), // The Eve before Christmas
                new DateTime(startDay.Year, 12, 25), // Christmas Eve
                new DateTime(startDay.Year, 12, 26) // The day after Christmas Eve
            };

            int period = Math.Abs((startDay - endDay).Days);
            int workDaysCounter = 0;
            int holidaysCounter = 0;

            for (int i = 0; i < period; i++)
            {

                if (startDay.DayOfWeek != DayOfWeek.Saturday && startDay.DayOfWeek != DayOfWeek.Sunday)
                {
                    for (int j = 0; j < holidays.Length; j++)
                    {
                        if (startDay==holidays[j])
                        {
                            holidaysCounter++;
                        }
                    }
                    workDaysCounter++;
                }
                
                startDay = startDay.AddDays(1);
            }
            return workDaysCounter-holidaysCounter;
        }
    }
}
